import { _decorator, Component, Node } from 'cc';
import customList from './customList';
import { worldRankData } from './RankTestData';
import { WorldRankItem } from './WorldRankItem';
const { ccclass, property } = _decorator;

@ccclass('WorldRank')
export class WorldRank extends Component {

    @property({ type: [Node], tooltip: '世界榜列表前三' })
    top3: Node[] = [];
    
    @property({ type: customList, tooltip: '世界榜列表其它' })
    list: customList = null;

    @property({ type: Node, tooltip: '我的排名' })
    myRank: Node = null; 

    start() {
        this.initTop3();
        this.initWorldRankList();
    }

    /** 初始化前三名和我自己 */
    initTop3() {
        this.top3.forEach((v, i)=> {
            const rankData = worldRankData[i];
            v.getComponent(WorldRankItem).init(rankData);
        });
        this.myRank.getComponent(WorldRankItem).init(worldRankData[33]);
    }

    /** 初始化世界榜列表 */
    initWorldRankList() {
        this.list.numItems = worldRankData.length - 3;
    }

    /** 初始化世界榜列表元素 */
    initWorldRankItem(node: Node, i: number) {
        const rankData = worldRankData[i + 3];
        node.getComponent(WorldRankItem).init(rankData);
    }


}

